const jwt = require('jsonwebtoken')
const mysecret = 'mysecret'
const Token = async (req) => {
    const token = await jwt.sign({ _id: req.body.username }, mysecret, { expiresIn: 60 * 60 * 24 });
    return token
};
const checkToken = async (ctx, next) => {
    // console.log(ctx);
    try {
        await jwt.verify(ctx.header.authorization, mysecret);
    } catch (err) {
        ctx.msg = '登录信息过期~,请重新登录'
        ctx.code = 302
        return false
    }
    next()
}


module.exports = {
    Token,
    mysecret,
    checkToken
}
